package com.example.zg.zg_312_ordering_new.model;

import com.example.zg.zg_312_ordering_new.beans.Comment;
import com.example.zg.zg_312_ordering_new.beans.UserinfoBean;
import com.example.zg.zg_312_ordering_new.common.Constants;
import com.example.zg.zg_312_ordering_new.listener.ListListener;
import com.example.zg.zg_312_ordering_new.listener.RetrofitListener;
import com.example.zg.zg_312_ordering_new.listener.UserinfoListener;
import com.example.zg.zg_312_ordering_new.services.CommentService;
import com.example.zg.zg_312_ordering_new.services.ShopService;
import com.example.zg.zg_312_ordering_new.services.UserinfoService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CommentModel{
    private Retrofit retrofit;

    public CommentModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getAllComment(int food_id, final ListListener listListener) {
        CommentService userinfoService=retrofit.create(CommentService.class);
        Call<List<Comment>> call=userinfoService.getFoodByShop(food_id);
        call.enqueue(new Callback<List<Comment>>() {
            @Override
            public void onResponse(Call<List<Comment>> call, Response<List<Comment>> response) {
                if(response.isSuccessful()&&response!=null)
                    listListener.onResponse(response.body());
                else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Comment>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
}
